define [], () ->

  'use strict'

  # DaoFatory Singleton
  # =============================================================

  DaoFactory =
    registry      : {}
    instanceCache : {}

    # Register a new DAO
    # ------------------

    register: (daoName, daoClass) ->
      @registry[daoName] = daoClass if not _.has @registry, daoName

    # Get a DAO by its name
    # ------------------

    getDAOByName: (daoName) ->
      throw new Error "DAO with name " + daoName + " not found" if not _.has @registry, daoName

      unless _.contains _.keys(this.instanceCache), daoName
        @instanceCache[daoName] = new this.registry[daoName]
        instance = @instanceCache[daoName]
        instance.setBaseUrl window.AppData.API_URL + instance.baseUrl

      @instanceCache[daoName]